(function (_window) {
    var
	gg = function (a) {
	    return document.getElementById(a);
	},
	drap = function (_self, _parent) {
	    var dr = this,
		a = gg(_self) || _self,
		b = gg(_parent) || _parent,
		x,
		y;
	    dr.go = function (e) {
	        if (!e) e = window.event;
	        if (e.button != 2) {
	            x = e.clientX - b.offsetLeft;
	            y = e.clientY - b.offsetTop;
	            document.onmousemove = mousemove;
	            document.onmouseup = function () {
	                document.onmousemove = null;
	            };
	        };
	    };
	    function mousemove(e) {
	        if (!e) e = window.event;
	        var
			t,
			l,
			r,
			m;
	        l = (e.clientX - x);
	        t = (e.clientY - y);
	        r = (gww() - b.offsetWidth);
	        m = (gwh() - b.offsetHeight);
	        b.style.left = (l <= 0 ? 0 : l >= r ? r : l) + "px";
	        b.style.top = (t <= 0 ? 0 : t >= m ? m : t) + "px";
	    };
	},
	bw = function () {
	    return (navigator.userAgent.indexOf('Chrome') > -1)
		|| (navigator.userAgent.indexOf('Safari') > -1);
	},
	gwh = function () {
	    var windowHeight = document.documentElement.clientHeight,
	    selfHeight = document.body.offsetHeight,
	    i = 0;
	    if (selfHeight < windowHeight) {
	        i = windowHeight;
	        
	    } else {
	        i = selfHeight;
	    };

	    return i;
	},
	gww = function () {
	    var windowWidth = document.documentElement.clientWidth,
		selfWidth = document.body.offsetWidth,
		i = 0;
	    if (selfWidth < windowWidth) {
	        i = windowWidth;
	    } else {
	        i = selfWidth;
	    };
	    return i;
	},
	gch = function () { return document.documentElement.clientHeight; },
	creElm = function (o, t, a) {
	    var b = document.createElement(t || 'div');
	    if (a) {
	        for (var p in o) {
	            p == 'style' ? b[p].cssText = o[p] : b[p] = o[p]
	        };
	        if (t == 'iframe') {
	            b.setAttribute('frameborder', '0', 0);
	        };
	        return a.appendChild(b);
	    }
	},
	sc = function (f, l) {
	    if (f) {
	        for (var i in l) {
	            f.style[i] = l[i];
	        };
	    };
	},
	exec = function (f) {
	    return f();
	},
	back_zIndex = 1000,
	panl_zIndex = 1001,
	JElass = {
	    Base: function () {
	        var jf = this,
			_b,
			_f,
			_t,
			_back,
			_boot_div_messag,
			_boot_div_button,
			_type,
			_height,
			_width,
			_title,
			_message,
			_buttonList,
			_delay,
			_url,
			_ready,
			_back,
			_cfun,
			_isClose,
			_isMin,
			_isMin1,
			_isMin2,
			_css,
			_list,
			_drop,
			_target;
	        jf.initiali = function (f) {
	            /*
	            参数大全
	            {
	            back        : 弹出层背景是否存在 (false 默认存在, true 不存在)
	            target      : 是否以新窗口模式弹出(是'_black')
	            height      : 高度
	            width       : 宽度
	            tle         : 标题 (Load方法没有)
	            msg         : 消息内容
	            buttonList  : 按钮内容集合 格式 [{ id: '可以为空', text: <按钮文字>, bak: function(){<点击事件>} }]
	            delay       : Load方法加载延迟执行函数的时间 (Load方法专用)
	            url         : 地址(open方法专用)
	            ready       : 窗口打开成功后执行方法
	            isClose     : 是否存在关闭按钮 (Load方法不存在)
	            isMin       : 是否存在最小化按钮( open方法专用 )
	            bak         : 方法(默认确认按钮点击事件 Load open 方法不存在)
	            cfun        : 方法(窗口关闭按钮事件)
	            css         : 样式字符串
	            drop        : 是否支持拖动 (false 默认存在, true 不存在  Load方法不存在)
	            }
	            */
	            panl_zIndex++;
	            back_zIndex = panl_zIndex - 1;
	            _type = f.type || 'iframe';
	            _back = f.back || false;
	            _target = f.target || '';
	            _b = _back ? null : _target == '_black' ? (creElm(
							{
							    className: 'ElassPanl',
							    style: 'z-index:' + (back_zIndex) + ';'
							}, 'div', document.body))
				: (gg("ElassPanl") || creElm(
							{
							    className: 'ElassPanl',
							    id: 'ElassPanl',
							    style: 'z-index:' + (back_zIndex) + ';'
							}, 'div', document.body));

	            _f = _target == '_black' ? (creElm(
							{
							    className: 'ElassBase' + (f.class1 ? (' ' + f.class1) : '') + '',
							    style: 'z-index:' + (panl_zIndex) + ';'
							}, 'div', document.body))
				: (gg("ElassBase") || creElm(
							{
							    className: 'ElassBase' + (f.class1 ? (' ' + f.class1) : ''),
							    id: 'ElassBase',
							    style: 'z-index:' + (panl_zIndex) + ';'
							}, 'div', document.body));

	            _height = f.height || 'auto';
	            _width = f.width || 300;
	            _title = f.tle || '系统提示:';
	            _message = f.msg || 'Load...';
	            _buttonList = f.buttonList || (f.type == 'confirm' ? [
					{ text: "确 认", bak: function () { _back(); } },
					{ text: "取 消", bak: function () { jf.hide(); } }
	            ] : f.type == 'alert' ? [
					{ text: "确 认", bak: function () { _back(); } }
	            ] : []);
	            _delay = f.delay || 0;
	            _url = f.url || 'about:Tabs';
	            _raady = f.ready || function () { };
	            _isClose = f.isClose || false;
	            _isMin = f.isMin || false;
	            _isMin1 = f.isMin1 || false;
	            _isMin2 = f.isMin2 || false;
	            _back = f.bak || jf.hide;
	            _cfun = f.cfun || jf.hide;
	            _css = f.css || '';
	            _list = f || {};
	            _drop = f.drop || false;
	            jf.drawLayer();
	            jf.drawClass();
	        };
	        function clear() {
	            while (_f.hasChildNodes()) {
	                _f.removeChild(_f.firstChild);
	            };
	        };
	        jf.drawLayer = function () {
	            clear();
	            var
				div1 = creElm({ className: 'e1' }, 'div', _f),
				div2 = creElm({ className: 'e2' }, 'div', _f),
				body = creElm({ className: _isMin2 ? 'body1' : 'body' }, 'div', _f),
				context = creElm({ className: 'context' }, 'div', body),
				ctle = _type == 'load' ? null : creElm({
				    innerHTML: _title,
				    className: _isMin2 ? 'tle1' : 'tle', //hele 2014-07-02 广告老样式
				    onclick: function () {
				        panl_zIndex++;
				        _f.style.zIndex = panl_zIndex;
				    },
				    onmousedown: _drop ? null : (function (e) {
				        panl_zIndex++;
				        ctle.style.cursor = 'move';
				        _f.style.zIndex = panl_zIndex;
				        new drap(ctle, _f).go(e);
				    })
				}, 'div', context),
				ctle_bnn = creElm({}, 'div', ctle),
	            /*关闭*/
				chide = _isClose ? null : creElm({
				    title: '关闭当前窗口',
				    className: 'bb_1 ff_1',
				    onmouseover: function () { this.className = 'bb_1 ff_1'; },
				    onmouseout: function () { this.className = 'bb_1 ff_1'; },
				    onclick: function () {
				        /*var 
				        _f_height = _f.offsetHeight;
				        _f_width  = _f.offsetWidth;
				        _f_top    = _f.offsetTop;
				        _f_left   = _f.offsetLeft;
				        _c_height = tb_context.offsetHeight,
				        zIndex    = [
				        _f_height,
				        _f_width,
				        _f_top,
				        _f_left,
				        _c_height
				        ],
				        _from     = 100,
				        $$        = null,
				        _w        = gww();
				        _h        = gwh();
				        var iHeight, iWidth, iLeft, iTop;
				        $$ = setInterval(
				        function(){
				        _from = _from - 8;
				        if(_from <= 0){
				        _cfun();
				        clearInterval($$);
				        return (false);
				        };
				        iHeight = parseInt(_f_height * (_from / 100));
				        iWidth  = parseInt(_f_width * (_from / 100));
				        sc(_f, {
				        height    : iHeight + 'px',
				        width     : iWidth + 'px',
				        left      : (_w - iWidth) / 2 + 'px',
				        top       : (_h - iHeight) / 2 + (bw() ? document.body.scrollTop : document.documentElement.scrollTop) + 'px'
				        });
				        sc(tb_context, {
				        height    : (parseInt(_c_height * (_from / 100))) + 'px'
				        });
				        }, 25
				        );*/
				        _cfun();
				    }
				}, 'b', ctle_bnn),
	            /*刷新*/
				crerh = _type == 'iframe' ? _isMin1 ? null : creElm({
				    className: 'bb_2',
				    title: '刷新当前页',
				    onmouseover: function () { this.className = 'bb_2 ff_2'; },
				    onmouseout: function () { this.className = 'bb_2'; },
				    onclick: function () {
				        tb_qubr.src = (tb_qubr.src.indexOf('?') < 0 ? tb_qubr.src + "?_pass=" : tb_qubr.src + "&_pass=") + (new Date().getTime().toString(36));
				    }
				}, 'b', ctle_bnn) : null,
	            /*全屏*/
				cfull = _type == 'iframe' ? _isMin1 ? null : creElm({
				    title: '窗口全屏幕',
				    className: 'bb_3',
				    onmouseover: function () { this.className == 'ff_3_qq' ? '' : this.className = 'bb_3 ff_3'; },
				    onmouseout: function () { this.className == 'ff_3_qq' ? '' : this.className = 'bb_3'; },
				    onclick: function () {
				        if (
							this.className == 'bb_3 ff_3' ||
							this.className == 'bb_3'
						) {
				            this.className = 'ff_3_qq';
				            this.title = '回到全屏窗口';
				            sc(_f, {
				                height: (gch() - 2) + 'px',
				                width: gww() + 'px',
				                left: '0px',
				                top: '1px'
				            });
				            sc(tb_context, {
				                height: gch() - 2 - 43 + 'px'
				            });
				        } else {
				            this.className = 'bb_3';
				            this.title = '窗口全屏幕';
				            sc(_f, {
				                height: _height == 'auto' ? 'auto' : _height + 'px',
				                width: _width + 'px',
				                display: 'block',
				                left: (gww() - parseInt(_width)) / 2 + 'px',
				                top: (gch() - (_height == 'auto' ? _f.offsetHeight : _height)) / 2 +
											(bw() ? document.body.scrollTop : document.documentElement.scrollTop) + 'px'
				            });
				            sc(tb_context, {
				                height: _height - 2 - 43 + 'px'
				            });
				        };
				    }
				}, 'b', ctle_bnn) : null,
				cMinimize = _type == 'iframe' ? _isMin ? null : creElm({
				    title: '窗口最小化',
				    className: 'bb_4',
				    onmouseover: function () { this.className = 'bb_4 ff_4'; },
				    onmouseout: function () { this.className = 'bb_4'; },
				    onclick: function () {
				        _t = gg('ElassTop') || creElm({ id: 'ElassTop' }, 'div', document.body);
				        var
						itm = creElm({
						    className: 'item',
						    onmouseover: function () { this.className = 'item iffos'; },
						    onmouseout: function () { this.className = 'item'; },
						    title: _title
						}, 'div', _t),
						hrf = creElm({
						    href: _url,
						    className: 'hrf',
						    innerHTML: _title,
						    onclick: function () {
						        jf.open(_list);
						        _t.removeChild(this.parentNode);
						        if (_t.getElementsByTagName('div').length == 0) {
						            document.body.removeChild(_t);
						        };
						        return (false);
						    }
						}, 'p', itm),
						bbn = creElm({
						    className: 'bbn',
						    title: '删除小标签',
						    onclick: function () {
						        _t.removeChild(this.parentNode);
						        if (_t.getElementsByTagName('div').length == 0) {
						            document.body.removeChild(_t);
						        };
						    }
						}, 'b', itm);
				        jf.hide();
				    }
				}, 'b', ctle_bnn) : null,
				tb_context = creElm({
				    className: 'tbs_context',
				    style: _height == 'auto' ? '' : 'height:' + (parseInt(_height) - (/(iframe|load)/.test(_type) ? 43 : 78)) + 'px'
				}, 'div', context),
				tb_qubr = _type == 'iframe' ? creElm({
				    name: 'iframe_mozzle',
				    scrolling: 'yes',
				    width: '100%',
				    height: '100%',
				    src: _url
				}, 'iframe', tb_context) : creElm({
				    className: 'tbs_context_cc',
				    style: /(iframe|load)/.test(_type) ? '' : 'font-size:14px; color:#f30; padding:20px 20px;' + _css,
				    innerHTML: _type == 'load' ? '<div style=\'padding:20px 0;font-size:14px;text-align:center;color:#f30;' + _css + '\'>' + _message + '</div>' : _message
				}, 'div', tb_context),
				boot = /(iframe|load|prompt)/.test(_type) ? null : creElm({
				    className: 'tb_boot'
				}, 'div', context);
	            _boot_div_messag = creElm({
	                id: 'bdmessage',
	                innerHTML: ''
	            }, 'p', boot) || null,
				_boot_div_button = creElm({
				    id: 'bdbutton'
				}, 'div', boot) || null,
				div3 = creElm({ className: 'e2' }, 'div', _f),
				div4 = creElm({ className: 'e1' }, 'div', _f);
	        };
	        jf.drawClass = function () {
	            var
				w = gww(),
				h = gwh();
	            sc(_b, {
	                height: h + 'px',
	                width: w + 'px',
	                display: 'block'
	            });
	            sc(_f, {
	                height: _height == 'auto' ? 'auto' : _height + 'px',
	                width: _width + 'px',
	                display: 'block',
	                left: (w - parseInt(_width)) / 2 + 'px'
	            });
	            _raady();
	            sc(_f, {
	                top: (gch() - (_height == 'auto' ? _f.offsetHeight : _height)) / 2 +
					(bw() ? document.body.scrollTop : document.documentElement.scrollTop) + 'px'
	            });
	        };
	        jf.hide = function () {
	            if (_b) {
	                document.body.removeChild(_b);
	            };
	            if (_f) {
	                document.body.removeChild(_f);
	            };
	        };
	        jf.open = function (c) {
	            c.type = 'iframe';
	            c.height = c.height ? c.height : Math.round(gch() * 0.9);
	            c.width = c.width ? c.width : Math.round(gww() * 0.9);
	            jf.initiali(c);
	        };
	        jf.load = function (c) {
	            c.type = 'load';
	            jf.initiali(c);
	            _delay == 0 ? exec(function () {
	                _back();
	            }) : exec(function () {
	                var yc = setTimeout(
						function () {
						    clearTimeout(yc);
						    _back();
						}, _delay * 1000
					);
	            });
	        };
	        jf.confirm = function (c) {
	            c.type = 'confirm';
	            jf.initiali(c);
	            jf.createButtonList();
	        };
	        jf.alert = function (c) {
	            c.type = 'alert';
	            jf.initiali(c);
	            jf.createButtonList();
	        };
	        jf.prompt = function (c) {
	            c.type = 'prompt';
	            jf.initiali(c);
	            jf.createButtonList();
	        };
	        jf.createButtonList = function () {
	            var b;
	            for (var k in _buttonList) {
	                (function (f) {
	                    if (f.text != undefined) {
	                        b = creElm({
	                            id: f.id || '',
	                            innerHTML: f.text || '按 钮',
	                            onmouseover: function () {
	                                this.className = 'bfos';
	                            },
	                            onmouseout: function () {
	                                this.className = '';
	                            },
	                            onclick: function () {
	                                f.bak();
	                            }
	                        }, 'b', _boot_div_button)
	                    };
	                }(_buttonList[k]));
	            };
	        };
	        jf.err = function (s) {
	            _boot_div_messag.innerHTML = s;
	        };
	    }
	};
    _window.Elass = JElass;
})(window);
